<template>
	<view class="vegetationReport">
		<!-- /////////////////////////植被监测 - 基本/////////////////////////-->
		<view class="basic borderB20">
			<view class="one borderB1">
				<view class="left">
					<text class="lLabel baseFontLabel">样方编号：</text>
					<text class="lValue baseFontValue">{{ ids }}</text>
				</view>
				<view v-if="details != null" class="right">
					<text class="rLabel baseFontLabel">调查日期：</text>
					<text class="lValue baseFontValue">{{ details.cjsj }}</text>
				</view>
			</view>
			<view v-if="details != null" class="three borderB1">
				<view class="item">
					<view class="baseFontLabel">经度：</view>
					<view class="baseFontValue">{{ details.longitude }}</view>
				</view>
				<view class="item">
					<view class="baseFontLabel wsp">纬度：</view>
					<view class="baseFontValue">{{ details.latitude }}</view>
				</view>
				<view class="item">
					<view class="baseFontLabel">海拔：</view>
					<view class="baseFontValue">{{ details.altitude }}m</view>
				</view>
				<view class="item">
					<view class="baseFontLabel">坡度：</view>
					<view class="baseFontValue">
						{{ details.slope }}
						<text v-if="details.slope != '-'">°</text>
					</view>
				</view>
			</view>
			<view v-if="details != null" class="one">
				<view class="left">
					<text class="lLabel baseFontLabel">总盖度：</text>
					<text class="lValue baseFontValue">{{ details.total_coverage }}</text>
				</view>
				<view class="right">
					<text class="rLabel baseFontLabel">草群平均高度：</text>
					<text class="lValue baseFontValue">{{ details.aver_height }} cm</text>
				</view>
			</view>
		</view>
		<!-- /////////////////////////植被监测 - 盖度/////////////////////////-->
		<view class="chartsBase borderB20">
			<view class="titleWar">盖度</view>
			<view class="companyWar">
				<view class="company">单位：%</view>
				<view class="legend o3">{{ coverageOption.name }}</view>
			</view>
			<view class="charts-box"><l-echart ref="coverage"></l-echart></view>
		</view>
		<!-- /////////////////////////植被监测 - 密度/////////////////////////-->
		<view class="chartsBase borderB20">
			<view class="titleWar">密度</view>
			<view class="companyWar">
				<view class="company">单位：-</view>
				<view class="legend o4">{{ densityOption.name }}</view>
			</view>
			<view class="charts-box"><l-echart ref="density"></l-echart></view>
		</view>
		<!-- /////////////////////////植被监测 - 生殖枝/////////////////////////-->
		<view class="chartsBase borderB20">
			<view class="titleWar">生殖枝</view>
			<view class="companyWar">
				<view class="company">单位：CM</view>
				<view class="legend o1">{{ reproductiveBranchOption.name }}</view>
			</view>
			<view class="charts-box">
				<view class="charts-box"><l-echart class="charts" ref="reproductiveBranch"></l-echart></view>
			</view>
		</view>
		<!-- /////////////////////////植被监测 - 叶层/////////////////////////-->
		<!-- <view class="chartsBase borderB20">
			<view class="titleWar">叶层</view>
			<view class="companyWar">
				<view class="company">单位：CM</view>
				<view class="legend o2">{{ leafLayerOption.name }}</view>
			</view>
			<view class="charts-box"><l-echart ref="leafLayer"></l-echart></view>
		</view> -->
		<!-- /////////////////////////植被监测 - 样方/////////////////////////-->
		<!-- <view class="quadratWar">
			<picker @change="choseListFun" :value="choseIndex" range-key="name" :range="list">
				<view class="quadrat">
					<view class="left">{{ list[choseIndex].name }}</view>
					<view class="iconfont">&#xe646;</view>
				</view>
			</picker>

			<view class="tabWar">
				<view class="row tabTitle">
					<view class="item">种类</view>
					<view class="item">鲜重</view>
					<view class="item">干重</view>
				</view>
				<view class="row" v-for="(item, index) in choseList" :key="index">
					<view class="item">{{ item.name }}</view>
					<view class="item">{{ item.xz }}</view>
					<view class="item">{{ item.gz }}</view>
				</view>
			</view>
		</view> -->
	</view>
</template>

<script>
import * as echarts from '@/uni_modules/lime-echart/components/l-echart/echarts';
export default {
	name: 'vegetationReport',
	props: {
		ids: {
			type: [Number, String],
			default: 0
		},
		vegetationData: {
			type: [Object, Array],
			default: () => {
				return null;
			}
		}
	},
	watch: {
		vegetationData: function(value) {
			if (value != null && value.hasOwnProperty('info')) {
				let info = value.info;
				const result1 = info.find(item => item.key === '生殖枝');
				this.reproductiveBranchOption = {
					name: result1.name,
					color: ['#13B5B1'],
					grid: [{ left: '10%', top: '5%', right: '5%' }],
					tooltip: {
						trigger: 'axis'
					},
					xAxis: {
						data: result1.x,
						type: 'category',
						boundaryGap: false,
						axisTick:{
							inside: true,
						},
						axisLine: {
							show: false
						},
						axisLabel: this.axisLabel,
						boundaryGap: ['1%', '1%'],
						minInterval: 1,
						max: 'dataMax',
						scale: true
					},
					yAxis: {
						type: 'value',
						min: function(value) {
							return 0;
						},
						max: function(value) {
							return value.max;
						},
						nameTextStyle: {
							padding: [5, 5, 5, 5]
						}
					},
					series: [
						{
							data: result1.data,
							type: 'bar',
							smooth: true,
							barWidth: 16,
							itemStyle: {
								borderRadius: 50
							}
						}
					]
				};
				this.$nextTick(function() {
					this.$refs.reproductiveBranch.init(config => {
						const { canvas } = config;
						const chart = echarts.init(canvas, null, config);
						chart.setOption(this.reproductiveBranchOption);
						return chart;
					});
				});
				// const result2 = info.find(item => item.key === '叶层');
				// this.leafLayerOption = {
				// 	name: result2.name,
				// 	color: ['#F29B76'],
				// 	xAxis: {
				// 		data: result2.x,
				// 		type: 'category',
				// 		boundaryGap: false,
				// 		axisTick:{
				// 			inside: true,
				// 		},
				// 		axisLine: {
				// 			show: false
				// 		},
				// 		axisLabel: this.axisLabel,
				// 		boundaryGap: ['1%', '1%'],
				// 		minInterval: 1,
				// 		max: 'dataMax',
				// 		scale: true
				// 	},
				// 	grid: [{ left: '10%', top: '5%', right: '5%' }],
				// 	yAxis: {
				// 		type: 'value'
				// 	},
				// 	series: [
				// 		{
				// 			data: result2.data,
				// 			type: 'line',
				// 			smooth: true
				// 		}
				// 	]
				// };
				// this.$nextTick(function() {
				// 	this.$refs.leafLayer.init(config => {
				// 		const { canvas } = config;
				// 		const chart = echarts.init(canvas, null, config);
				// 		chart.setOption(this.leafLayerOption);
				// 		return chart;
				// 	});
				// });
				const result3 = info.find(item => item.key === '盖度');
				this.coverageOption = {
					name: result3.name,
					color: ['#00A0E9'],
					tooltip: {
						trigger: 'axis'
					},
					xAxis: {
						data: result3.x,
						type: 'category',
						boundaryGap: false,
						axisTick:{
							inside: true,
						},
						axisLine: {
							show: false
						},
						axisLabel: this.axisLabel,
						boundaryGap: ['1%', '1%'],
						minInterval: 1,
						max: 'dataMax',
						scale: true
					},
					grid: [{ left: '10%', top: '5%', right: '5%' }],
					yAxis: {
						type: 'value'
					},
					series: [
						{
							data: result3.data,
							type: 'bar',
							smooth: true,
							barWidth: 16,
							itemStyle: {
								borderRadius: 50
							}
						}
					]
				};
				this.$nextTick(function() {
					this.$refs.coverage.init(config => {
						const { canvas } = config;
						const chart = echarts.init(canvas, null, config);
						chart.setOption(this.coverageOption);
						return chart;
					});
				});
				// density
				const result4 = info.find(item => item.key === '密度');
				this.densityOption = {
					name: result4.name,
					color: ['#80C269'],
					grid: [{ left: '10%', top: '5%', right: '5%' }],
					tooltip: {
						trigger: 'axis'
					},
					xAxis: {
						data: result4.x,
						type: 'category',
						boundaryGap: false,
						axisTick:{
							inside: true,
						},
						axisLine: {
							show: false
						},
						axisLabel: this.axisLabel,
						boundaryGap: ['1%', '1%'],
						minInterval: 1,
						max: 'dataMax',
						scale: true
					},
					yAxis: {
						type: 'value'
					},
					series: [
						{
							data: result4.data,
							type: 'bar',
							smooth: true,
							barWidth: 16,
							itemStyle: {
								borderRadius: 50
							}
						}
					]
				};
				this.$nextTick(function() {
					this.$refs.density.init(config => {
						const { canvas } = config;
						const chart = echarts.init(canvas, null, config);
						chart.setOption(this.densityOption);
						return chart;
					});
				});
			}
		}
	},
	computed: {
		details: function({ vegetationData }) {
			let value = null;
			if (vegetationData != null) {
				value = vegetationData.pt[0];
			}
			return value;
		},
		list: function({ vegetationData }) {
			let value = [
				{
					name: '第一个样方（g/m2）',
					list: []
				},
				{
					name: '第二个样方（g/m2）',
					list: []
				},
				{
					name: '第三个样方（g/m2）',
					list: []
				}
			];
			let nameList = {
				1: '第一个样方（g/m2）',
				2: '第二个样方（g/m2）',
				3: '第三个样方（g/m2）'
			};
			if (vegetationData != null) {
				let values = vegetationData.yfMess;
				let i = 0;
				for (let item in values) {
					let name;
					value.splice(i++, 1, {
						name: nameList[item],
						list: values[item]
					});
				}
			}
			return value;
		},
		choseList: function({ list, choseIndex }) {
			let value = [];
			if (list.length > 0) {
				value = list[choseIndex].list;
			}
			return value;
		}
	},
	data() {
		return {
			axisLabel: {
				interval: 0,
				formatter: function(value) {
					debugger;
					var ret = ''; //拼接加\n返回的类目项
					var maxLength = 1; //每项显示文字个数
					var valLength = value.length; //X轴类目项的文字个数
					var rowN = Math.ceil(valLength / maxLength); //类目项需要换行的行数
					if (rowN > 1) {
						//如果类目项的文字大于3,
						for (var i = 0; i < rowN; i++) {
							var temp = ''; //每次截取的字符串
							var start = i * maxLength; //开始截取的位置
							var end = start + maxLength; //结束截取的位置
							//这里也可以加一个是否是最后一行的判断，但是不加也没有影响，那就不加吧
							temp = value.substring(start, end) + '\n';
							ret += temp; //凭借最终的字符串
						}
						return ret;
					} else {
						return value;
					}
				}
			},
			reproductiveBranchOption: {},
			leafLayerOption: {},
			coverageOption: {},
			densityOption: {},
			choseIndex: 0,
			quadratList: []
		};
	},
	mounted() {
		this.$nextTick(function() {
			this.$refs.leafLayer.init(config => {
				const { canvas } = config;
				const chart = echarts.init(canvas, null, config);
				chart.setOption(this.leafLayerOption);
				return chart;
			});
		});
	},
	onReady() {},
	methods: {
		choseListFun(e) {
			this.choseIndex = e.target.value;
		}
	},
	components: {}
};
</script>

<style lang="scss" scoped>
@import '@/common/css/asd.scss';
.vegetationReport {
	@include aReport(280);
	.chartsBase {
		display: flex;
		flex-direction: column;
		align-items: stretch;
		justify-content: flex-start;
		@include chartsBase();
		.companyWar {
			position: relative;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: flex-start;
			font-size: 24rpx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #666666;
			line-height: 1;
			height: 25rpx;
			box-sizing: border-box;
			padding: 0 0 0 28rpx;
			.company {
				// flex: 1;
				margin-right: 212rpx;
			}
			.legend {
				flex: 1;
				position: relative;
				align-items: center;
				justify-content: flex-start;
				display: flex;
				&::after {
					position: absolute;
					content: '';
					width: 31rpx;
					height: 4rpx;
					top: 50%;
					left: -39rpx;
					transform: translateY(-50%);
				}
				&.o1::after {
					background-color: #13b5b1;
				}
				&.o2::after {
					background-color: #f29b76;
				}
				&.o3::after {
					width: 10rpx;
					height: 16rpx;
					left: -20rpx;
					border-radius: 5rpx;
					background-color: #00a0e9;
				}
				&.o4::after {
					width: 10rpx;
					height: 16rpx;
					left: -20rpx;
					border-radius: 5rpx;
					background-color: #80c269;
				}
			}
		}
	}
	.charts-box {
		box-sizing: border-box;
		// padding: 0 30rpx 30rpx 30rpx;
		height: 516rpx;
		.charts {
			width: 100%;
			height: 516rpx;
		}
	}
	.quadratWar {
		box-sizing: border-box;
		padding: 30rpx 0 0 0;
		.quadrat {
			min-height: 90rpx;
			background-color: #e8f4f8;
			border-radius: 8rpx;
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			align-items: center;
			font-size: 32rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #5c6a70;
			box-sizing: border-box;
			padding: 0 30rpx 0 40rpx;
			margin: 0 24rpx 30rpx 36rpx;
			.iconfont {
				font-size: 14rpx;
				color: #00a0e9;
			}
		}
		.tabWar {
			@include ejectList(3);
		}
	}
}
</style>
